package org.gurms.service;

import java.util.List;

import org.gurms.dao.po.system.SysMenu;
import org.gurms.dao.po.system.SysRole;
import org.gurms.dao.po.system.SysUser;
import org.gurms.service.dto.system.MenuDto;
import org.gurms.service.dto.system.UserDto;

public class PojoConvert {

	public static UserDto convert(SysUser src){
		if(src == null)
			return null;
		
		UserDto dest = new UserDto();
		dest.setErrorcount(src.getErrorcount());
		dest.setLogincount(src.getLogincount());
		dest.setLogindate(src.getLogindate());
		dest.setLoginip(src.getLoginip());
		dest.setLoginpassword(src.getLoginpassword());
		dest.setLogintime(src.getLogintime());
		dest.setOnlineflag(src.getOnlineflag());
		dest.setOrgid(src.getSysorg().getOrgid());
		dest.setUserid(src.getUserid());
		dest.setUsername(src.getUsername());
		dest.setUserstatus(src.getUserstatus());
		List<SysRole> roles = src.getSysroles();
		for(SysRole role : roles){
			dest.getRoles().add(role.getRoleid());
		}
		
		return dest;
	}
	
	public static MenuDto convert(SysMenu src){
		if(src == null)
			return null;
		
		MenuDto dest = new MenuDto();
		dest.setLeafflag(src.getLeafflag());
		dest.setMenuid(src.getMenuid());
		dest.setMenuname(src.getMenuname());
		dest.setMenuorder(src.getMenuorder());
		dest.setMenustatus(src.getMenustatus());
		dest.setMenuurl(src.getMenuurl());
		dest.setPrivilegelist(src.getPrivilegelist());
		dest.setRemark(src.getRemark());
		dest.setParentmenu(src.getParentmenu().getMenuid());
		
		return dest;
	}
	
	public static void convertTreeList(List<MenuDto> list, SysMenu src){
		if(src == null)
			return;
		
		List<SysMenu> sub = src.getSubmenus();
		for(SysMenu menu : sub){
			convertTreeList(list, menu);
		}
		
		MenuDto dest = convert(src);
		list.add(0, dest);
	}
}
